package com.tudouji.project.copy.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tudouji.framework.aspectj.lang.annotation.Log;
import com.tudouji.framework.aspectj.lang.enums.BusinessType;
import com.tudouji.project.copy.domain.Copyparam;
import com.tudouji.project.copy.service.ICopyparamService;
import com.tudouji.framework.web.controller.BaseController;
import com.tudouji.framework.web.domain.AjaxResult;
import com.tudouji.common.utils.poi.ExcelUtil;
import com.tudouji.framework.web.page.TableDataInfo;

/**
 * 同步参数Controller
 * 
 * @author wf
 * @date 2020-12-30
 */
@RestController
@RequestMapping("/copy/copyparam")
public class CopyparamController extends BaseController
{
    @Autowired
    private ICopyparamService copyparamService;

    /**
     * 查询同步参数列表
     */
    @PreAuthorize("@ss.hasPermi('copy:copyparam:list')")
    @GetMapping("/list")
    public TableDataInfo list(Copyparam copyparam)
    {
        startPage();
        List<Copyparam> list = copyparamService.selectCopyparamList(copyparam);
        return getDataTable(list);
    }

    /**
     * 导出同步参数列表
     */
    @PreAuthorize("@ss.hasPermi('copy:copyparam:export')")
    @Log(title = "同步参数", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Copyparam copyparam)
    {
        List<Copyparam> list = copyparamService.selectCopyparamList(copyparam);
        ExcelUtil<Copyparam> util = new ExcelUtil<Copyparam>(Copyparam.class);
        return util.exportExcel(list, "copyparam");
    }

    /**
     * 获取同步参数详细信息
     */
    @PreAuthorize("@ss.hasPermi('copy:copyparam:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(copyparamService.selectCopyparamById(id));
    }

    /**
     * 新增同步参数
     */
    @PreAuthorize("@ss.hasPermi('copy:copyparam:add')")
    @Log(title = "同步参数", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Copyparam copyparam)
    {
        Copyparam c = new Copyparam();
        c.setType(copyparam.getType());
        List<Copyparam> copyparamList = this.copyparamService.selectCopyparamList(c);
        if(copyparamList.size() > 0){
            return AjaxResult.error("该类型已经添加过，不能重复添加");
        }
        return toAjax(copyparamService.insertCopyparam(copyparam));
    }

    /**
     * 修改同步参数
     */
    @PreAuthorize("@ss.hasPermi('copy:copyparam:edit')")
    @Log(title = "同步参数", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Copyparam copyparam)
    {
        Copyparam c = new Copyparam();
        c.setType(copyparam.getType());
        c.setId(copyparam.getId());
        List<Copyparam> copyparamList = this.copyparamService.selectCopyparamList(c);
        if(copyparamList.size() > 0){
            return AjaxResult.error("该类型已经添加过，不能重复添加");
        }
        return toAjax(copyparamService.updateCopyparam(copyparam));
    }

    /**
     * 删除同步参数
     */
    @PreAuthorize("@ss.hasPermi('copy:copyparam:remove')")
    @Log(title = "同步参数", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(copyparamService.deleteCopyparamByIds(ids));
    }
}
